text handle: Don't leak adjustments
authorMatthias Clasen <mclasen@redhat.com>
Wed, 23 Nov 2016 18:55:28 +0000 (13:55 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 23 Nov 2016 18:57:03 +0000 (13:57 -0500)
This can happen if the weak pointer is triggered before the
adjustments are unset. Pointed out in

https://bugzilla.gnome.org/show_bug.cgi?id=774790

gtk/gtktexthandle.c

index 19e89f1d1a57703fa3e64e18c4f862e2158f1e6b..04373fe70b9653629f3b493668c3d229819e9f0a 100644 (file)
@@ -458,25 +458,21 @@ _gtk_text_handle_set_scrollable (GtkTextHandle *handle,
 
   priv = handle->priv;
 
-  if (priv->parent_scrollable)
+  if (priv->vadj)
     {
-      if (priv->vadj)
-        {
-          g_signal_handlers_disconnect_by_data (priv->vadj, handle);
-          g_object_unref (priv->vadj);
-          priv->vadj = NULL;
-        }
+      g_signal_handlers_disconnect_by_data (priv->vadj, handle);
+      g_clear_object (&priv->vadj);
+    }
 
-      if (priv->hadj)
-        {
-          g_signal_handlers_disconnect_by_data (priv->hadj, handle);
-          g_object_unref (priv->hadj);
-          priv->hadj = NULL;
-        }
-      g_object_remove_weak_pointer (G_OBJECT (priv->parent_scrollable), (gpointer *) &priv->parent_scrollable);
+  if (priv->hadj)
+    {
+      g_signal_handlers_disconnect_by_data (priv->hadj, handle);
+      g_clear_object (&priv->hadj);
     }
 
+  if (priv->parent_scrollable)
+    g_object_remove_weak_pointer (G_OBJECT (priv->parent_scrollable), (gpointer *) &priv->parent_scrollable);
+
   priv->parent_scrollable = scrollable;
 
   if (scrollable)